<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>易抽奖-新建抽奖1</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="index.css" type="text/css">
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-lg-3 visible-xs-*"></div>
        <div class="col-lg-6" style="background-color:#DCDCDC"><br>
            <div align="center">
                <p class="button3">新建抽奖</p>
                <span class="font-new">创建人：</span>
                <span class="font-new" id="yibanname"></span><br>
                <span class="font-new">ID：</span>
                <span class="font" id="yibanid"></span>
            </div>
            <form>
                <p class="font2">活动名称:</p>
                <div align="center">
                    <input type="text" class="input" id="lotteryname"/>
                    <p class="font2">活动详情:</p>
                    <input type="text" class="input" id="lotteryintro" placeholder="包含活动时间地点"/>
                    <p class="font2">开始时间:</p>
                    <input class="input" type="datetime-local" name="lotterytime"/>
                    <p class="font2">结束时间:</p>
                    <input class="input" type="datetime-local" name="lotterytime"/>
                </div>
            </form>
            <br><br><br><br>
            <div align="center">
                <button type="button" class="button2"/>
                下一步</button><br><br><br><br></div>
        </div>
        <div class="col-lg-3 visible-xs-*"></div>
    </div>
</div>
</body>
<script>
    $(document).ready(function () {
        var userName = "";
        //展示用户信息
        $.post("http://yb.upc.edu.cn:8084/lottery/userInfo",
            {
                Authorization: localStorage.getItem("testtoken")
            },
            function (data) {
                userName = data.object.yibanname
                document.getElementById("yibanname").innerHTML = userName
                document.getElementById("yibanid").innerHTML = data.object.yibanid
            }
        )
        $("button").click(function () {
            //转换开始时间类型
            var str = document.getElementsByName('lotterytime')[0].value;
            var strArray = str.split('T');
            var strDate = strArray[0].split('-');
            var strTime = strArray[1].split(":");
            var date1 = strDate[0] + "-" + strDate[1] + "-" + strDate[2] + " " + strTime[0] + ":" + strTime[1] + ":00";

            //转换结束时间类型
            var str2 = document.getElementsByName('lotterytime')[1].value;
            var strArray2 = str.split('T');
            var strDate2 = strArray2[0].split('-');
            var strTime2 = strArray2[1].split(":");
            var date2 = strDate2[0] + "-" + strDate2[1] + "-" + strDate2[2] + " " + strTime2[0] + ":" + strTime2[1] + ":00";
            $.post("http://yb.upc.edu.cn:8084/lottery/createLottery",
                {
                    Authorization: localStorage.getItem("testtoken"),
                    userName: userName,
                    //活动名称
                    lotteryName: document.getElementById('lotteryname').value,
                    //活动描述
                    lotteryIntro: document.getElementById('lotteryintro').value,
                    //开始时间
                    lotteryTimeBegin: date1,
                    //结束时间
                    lotteryTimeEnd: date2
                },
                function (data) {
                    window.open("new2.html?passcode=" + data.object[1] + "&creatorId=" + data.object[2] + "&lotteryId=" + data.object[0] + "  ",'_self')
                }
            );

        })
    })
</script>
</body>
</html>
